home *** CD-ROM | disk | FTP | other *** search
- /* getc.c, from p. 440 of Turbo C Bible */
- #include <stdio.h>
- main()
- {
- FILE *infile;
- char buffer[81];
- int i, c;
- /* Open the file -- assuming its at */
- /* the root directory of C: */
- if ((infile = fopen ("c:\\config.sys", "r")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- c = getc(infile);
- for(i = 0; (i < 80) && (feof(infile) == 0) && (c != '\n'); i++)
- {
- buffer[i] = c;
- c = getc(infile);
- }
- buffer[i] = '\0'; /* to make a C-style string */
- printf("First line of c:config.sys: %s\n", buffer);
- }